home *** CD-ROM | disk | FTP | other *** search
- #include "fclasses.h"
- #include "fix.h"
-
- int PixelSize = 1;
-
- // ############################################################################
- // Constructors
-
- Flare::Flare (void)
- {
- xPos = yPos = xPlot = yPlot = ground = gravty = thrust = 0;
- gndTerminated = alive = FALSE;
- gravConst = (1 * Fixed) >> (random (3)+1);// gravity constant... this case it's random.
-
- // trailer buffer settings.
- overBuf = FALSE;
- bufPnt = -1;
- trailLen = 0;
- trailer = NULL;
- colour = RGB(255,255,255);
- }
-
- Flare::Flare (int x, int y,
- int thr, int grav,
- int cyc, int gnd,
- int trailLength, COLORREF col)
- {
- init (x, y, thr, grav, cyc, gnd, trailLength, col);
- }
-
- void Flare::init (int x, int y,
- int thr, int grav,
- int cyc, int gnd,
- int trailLength, COLORREF col)
- {
- xPos = x;
- yPos = y;
- thrust = thr;
- ground = gnd;
- cycles = cyc;
- colour = col;
- gravty = grav;
-
- // init internals ***** Change XPos, yPos and assign to xPlot, yPlot *****
- xPlot = yPlot = 0;
- gndTerminated = FALSE; // flare hasn't hit the ground!
- alive = TRUE;
-
- //**** Allocate trailer memory ****
- // If memory is already allocated, but trail length has changed. Then
- // delete/free memory.
- if ((trailer != NULL) && (trailLen != trailLength))
- {
- delete trailer;
- trailer = NULL;
- }
-
- // Allocate memory
- if (trailer == NULL)
- trailer = new SaveXY[trailLength];
-
- // buffer variables for trailer
- trailLen = trailLength;
- overBuf = FALSE;
- bufPnt = -1;
- }
-
- void Flare::removePoint (HDC hdc, int x, int y)
- {
- if (y > ground)
- y = ground;
-
- switch (PixelSize)
- {
- case 1:
- SetPixel(hdc, x, y, 0);
- break;
-
- case 2:
- SetPixel (hdc, x, y, 0);
- SetPixel (hdc, x, y+1, 0);
- break;
-
- case 3:
- SetPixel (hdc, x+1, y-1, 0);
- SetPixel (hdc, x, y, 0);
- SetPixel (hdc, x+1, y, 0);
- break;
-
- case 4:
- SetPixel(hdc, x, y, 0);
- SetPixel(hdc, x-1, y, 0);
- SetPixel(hdc, x, y-1, 0);
- SetPixel(hdc, x-1, y-1, 0);
- }
- }
-
- void Flare::showPoint (HDC hdc, int x, int y)
- {
- if (y > ground)
- y = ground;
-
- switch (PixelSize)
- {
- case 1:
- SetPixel(hdc, x, y, colour);
- break;
-
- case 2:
- SetPixel (hdc, x, y, colour);
- SetPixel (hdc, x, y+1, colour);
- break;
-
- case 3:
- SetPixel (hdc, x+1, y-1, colour);
- SetPixel (hdc, x, y, colour);
- SetPixel (hdc, x+1, y, colour);
- break;
-
- case 4:
- SetPixel(hdc, x, y, colour);
- SetPixel(hdc, x-1, y, colour);
- SetPixel(hdc, x, y-1, colour);
- SetPixel(hdc, x-1, y-1, colour);
- }
- }
-
- BOOL Flare::move (HDC hdc)
- {
- if (alive)// && (trailer != NULL))
- {
- // update flare
- if (trailLen > 0)
- {
- // decrement cycles of life for firework
- cycles--;
-
- yPlot = yPlot + gravty; // decrease virtical lift
- xPlot = xPlot + thrust; // decrease horizontal thrust
- gravty = gravty - gravConst; // update gravity pull
-
- // **** Trailer maintenace ****
- // load buffer from start
- if (overBuf == FALSE)
- {
- // If item exceeds buffer, rollover to start of buffer (queue system)
- if (bufPnt >= trailLen - 1)
- {
- bufPnt = -1;
- overBuf = TRUE;
-
- removePoint (hdc, trailer [bufPnt+1].x, trailer [bufPnt+1].y);
- }
-
- bufPnt++;
- trailer[bufPnt].x = xPos + (xPlot / Fixed);
- trailer[bufPnt].y = yPos - (yPlot / Fixed);
- }
- else // cycle thru queue buffer.
- {
- if (cycles <= trailLen)
- {
- removePoint (hdc, trailer [trailLen-1].x, trailer [trailLen-1].y);
- trailLen--;
- }
-
- if (bufPnt >= trailLen - 1)
- bufPnt = -1;
-
- bufPnt++;
- removePoint (hdc, trailer [bufPnt].x, trailer [bufPnt].y);
- trailer [bufPnt].x = xPos + (xPlot / Fixed);
- trailer [bufPnt].y = yPos - (yPlot / Fixed);
- }
-
- showPoint (hdc, trailer [bufPnt].x, trailer [bufPnt].y);
- }
- else
- {
- removePoint (hdc, trailer [0].x, trailer [0].y);
- alive = FALSE;
- }
- }
- return alive;
- }
-
- // ############################################################################
- // Destructor
- Flare::~Flare(void)
- {
- delete trailer;
- }
-
-
- // ############################################################################
- // ############################################################################
- // ############################################################################
-
- void SkyRocket::init (int starBNum,
- int x, int y,
- int thr, int grav,
- int cyc, int gnd,
- int trailLength, COLORREF col)
- {
- //**** Allocate explode memory ****
- // If memory is already allocated, but explode number has changed. Then
- // delete/free memory.
- if ((pStarBurst != NULL) && (starBurstNum != starBNum))
- {
- delete pStarBurst;
- pStarBurst = NULL;
- }
-
- if (pStarBurst == NULL)
- pStarBurst = new Flare[starBNum];
-
- // Initialise main rocket ....
- mainRocket.init (x, y, thr, grav, cyc, gnd, trailLength, col);
-
- // Initialise explode variables.
- explode = FALSE;
- starBurstNum = starBNum;
- colour = col;
- trailLen = trailLength;
-
- // Select colour item to change (i.e. increment!)
- // test for single primary colours
- const int incRocAmount = 3;
- int testRGB = GetRValue(colour);
- testRGB += GetGValue(colour);
- testRGB += GetBValue(colour);
-
-
- if (testRGB <= 256) // Only one colour is active
- {
- // Pick an primary item that isn't set!
- int pick = 0;
- while (pick == 0)
- {
- colItemChange = random (3);
- switch (colItemChange)
- {
- case 0:
- if (GetRValue(colour) < 127)
- pick = -1;
- break;
-
- case 1:
- if (GetGValue(colour) < 127)
- pick = -1;
- break;
-
- case 2:
- if (GetBValue(colour) < 127)
- pick = -1;
- }
- }
- }
- else
- colItemChange = random(3);
-
- // Select the increment style according to current colour value.
- switch (colItemChange)
- {
- // red
- case 0:
- if (GetRValue(colour) < 127)
- colChangeAmnt = incRocAmount;
- else
- colChangeAmnt = -incRocAmount;
- break;
-
- // green
- case 1:
- if (GetGValue(colour) < 127)
- colChangeAmnt = incRocAmount;
- else
- colChangeAmnt = -incRocAmount;
- break;
-
-
- // blue
- case 2:
- if (GetBValue(colour) < 127)
- colChangeAmnt = incRocAmount;
- else
- colChangeAmnt = -incRocAmount;
- break;
- }
- }
-
- BOOL SkyRocket::move (HDC hdc)
- {
- // If no memory allocated .... leave.
- if (pStarBurst == NULL)
- return FALSE;
-
- // Update main rocket, and then explode!
- if (explode == FALSE)
- {
- if (mainRocket.move(hdc) == FALSE)
- {
- // Set up explosion when main rocket dies.
- int x, y;
- explode = TRUE;
-
- // intialise star burst.
- mainRocket.getCurrentPos (x, y);
-
- // Implement random explosion type, two setup options exist.
- int count;
- switch (random(10))
- {
- case 0:
- // Implement bridel veil.
- for (count = 0; count < starBurstNum; count++)
- {
-
- pStarBurst[count].init (x,y,
- ((random (60)-30) * Fixed) >> random(2)+4, ((random (60)-20) * Fixed) >> random(2)+4,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 1:
- // Implement a super nova explosion.
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x, y,
- ((random (60)-30) * Fixed) >> random(4), ((random (60)-30) * Fixed) >> random(4),
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 2:
- // Circle small explosion.
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x + random (10)-5,y + random (10)-5,
- ((random (30)-15) * Fixed) >> random(2)+2, ((random (100)-10) * Fixed) >> random(2)+2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 3:
- // Circle small explosion.
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x + random (10)-5,y + random (10)-5,
- ((random (100)-50) * Fixed) >> random(2)+2, ((random (100)-10) * Fixed) >> random(4)+2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 4:
- // Circle small explosion.
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x + random (10)-5,y + random (10)-5,
- ((random (20)-random(20)) * Fixed) >> random(2)+1, ((random (20)-random(20)) * Fixed) >> random(2)+1,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 5:
- // Circle small explosion.
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x, y,
- ((random (10)-random(10)) * Fixed) >> 1, ((random (10)-random(10)) * Fixed) >> 1,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 6:
- // Downward explosion
- for (count = 0; count < starBurstNum; count++)
- {
- pStarBurst[count].init (x, y,
- ((random (100)-50) * Fixed) >> random(2)+2, ((random (50) - 35) * Fixed) >> random(2)+2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- break;
-
- case 7:
- {
- // Circular explosion.
- int r;
- int xSin;
- int yCos;
-
- for (count = 0; count < starBurstNum; count++)
- {
- r = random(NUMOFDEGREES);
- xSin = (int)((SIN (r) * random(100)+10) >> SHIFT);
- yCos = (int)((COS (r) * random(100)+10) >> SHIFT);
- pStarBurst[count].init (x+xSin, y+yCos,
- (yCos * Fixed) >> 2, (xSin * Fixed) >> 2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- }
- break;
-
- case 8:
- {
- // Circular explosion.
- int r;
- int xSin;
- int yCos;
-
- for (count = 0; count < starBurstNum; count++)
- {
- r = random(NUMOFDEGREES);
- xSin = (int)((SIN (r) * random(100)+10) >> SHIFT);
- yCos = (int)((COS (r) * random(100)+10) >> SHIFT);
- pStarBurst[count].init (x+xSin, y+yCos,
- (xSin * Fixed) >> 2, (yCos * Fixed) >> 2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- }
- break;
-
- case 9:
- {
- // Circular explosion.
- int r;
- int xSin;
- int yCos;
- int size = random(50)+10;
-
- for (count = 0; count < starBurstNum; count++)
- {
- r = random(NUMOFDEGREES);
- xSin = (int)((SIN (r) * size) >> SHIFT);
- yCos = (int)((COS (r) * size) >> SHIFT);
- pStarBurst[count].init (x+xSin, y-yCos,
- (random(xSin) * Fixed) >> 2, (random(yCos) * Fixed) >> 2,
- random(100), MAXY, random(trailLen)+5, colour);
- }
- }
- break;
- }
- }
- }
- else // Update flare explosion.
- {
- int aliveCount = starBurstNum;
-
- // Update and text each flare in the explosion, if all dead,
- // tell system.
- for (int count = 0; count < starBurstNum; count++)
- {
-
- if (pStarBurst[count].move(hdc) == FALSE)
- aliveCount--;
- else
- {
- COLORREF colChange = pStarBurst[count].getColour();
- int r = GetRValue(colChange);
- int g = GetGValue(colChange);
- int b = GetBValue(colChange);
-
- switch (colItemChange)
- {
- // Red
- case 0:
- r += colChangeAmnt;
- break;
-
- // Green
- case 1:
- g += colChangeAmnt;
- break;
-
- // Blue
- case 2:
- b += colChangeAmnt;
- break;
- }
-
- pStarBurst[count].setColour(RGB(r, g, b));
- }
- }
-
- // Return false if all flares are DEAD.
- if (aliveCount == 0)
- return FALSE;
- }
-
- return TRUE;
- }
-
- // ############################################################################
- // ############################################################################
- // ############################################################################
-
- void FlowerPot::init (int num, int x, int y, COLORREF col, int cyc, int tLen)
- {
- if (num <= 0)
- return;
-
- // Allocate memory.
- if ((pFlares != NULL) && (num != flareNum))
- {
- delete pFlares;
- pFlares = NULL;
- }
-
- if (pFlares == NULL)
- pFlares = new Flare[num];
-
- flareNum = num;
- colour = col;
- cycles = cyc;
- xPos = x;
- yPos = y;
- trailLen = tLen;
-
-
- // Select colour item to change (i.e. increment!)
- // test for single primary colours
- const int incFlwrAmount = 10;
- int testRGB = GetRValue(colour);
- testRGB += GetGValue(colour);
- testRGB += GetBValue(colour);
-
-
- if (testRGB <= 256) // Only one colour is active
- {
- // Pick an primary item that isn't set!
- int pick = 0;
- while (pick == 0)
- {
- colItemChange = random (3);
- switch (colItemChange)
- {
- case 0:
- if (GetRValue(colour) < 127)
- pick = -1;
- break;
-
- case 1:
- if (GetGValue(colour) < 127)
- pick = -1;
- break;
-
- case 2:
- if (GetBValue(colour) < 127)
- pick = -1;
- }
- }
- }
- else
- colItemChange = random(3);
-
- // Select the increment style according to current colour value.
- switch (colItemChange)
- {
- // red
- case 0:
- if (GetRValue(colour) < 127)
- colChangeAmnt = incFlwrAmount;
- else
- colChangeAmnt = -incFlwrAmount;
- break;
-
- // green
- case 1:
- if (GetGValue(colour) < 127)
- colChangeAmnt = incFlwrAmount;
- else
- colChangeAmnt = -incFlwrAmount;
- break;
-
-
- // blue
- case 2:
- if (GetBValue(colour) < 127)
- colChangeAmnt = incFlwrAmount;
- else
- colChangeAmnt = -incFlwrAmount;
- break;
- }
-
-
- // Setup inital flares !
- if (pFlares == NULL)
- return;
-
- for (int count = 0; count < flareNum; count++)
- {
- pFlares[count].init (xPos, yPos,
- ((random (10)-5) * Fixed) >> random(3)+1, (random (20) * Fixed) >> random(2)+1,
- random(50), yPos, trailLen, colour);
- }
- }
-
- BOOL FlowerPot::move (HDC hdc)
- {
- // If noting allocated, nothing to move.
- if (pFlares == NULL)
- return FALSE;
-
- if (cycles > 0)
- {
- cycles--;
- for (int count = 0; count < flareNum; count++)
- {
- // Update flares
- if (pFlares[count].move(hdc) == FALSE)
- {
- pFlares[count].init (xPos, yPos,
- ((random (10)-5) * Fixed) >> random(3)+1,
- (random (20) * Fixed) >> random(2)+1,
- random(50), yPos, trailLen, colour);
- }
- else
- {
- COLORREF colChange = pFlares[count].getColour();
- int r = GetRValue(colChange);
- int g = GetGValue(colChange);
- int b = GetBValue(colChange);
-
- switch (colItemChange)
- {
- // Red
- case 0:
- r += colChangeAmnt;
- break;
-
- // Green
- case 1:
- g += colChangeAmnt;
- break;
-
- // Blue
- case 2:
- b += colChangeAmnt;
- break;
- }
-
- pFlares[count].setColour(RGB(r, g, b));
- }
- }
- }
- else
- {
- int testAlive = 0;
-
- for (int count = 0; count < flareNum; count++)
- {
- if (pFlares[count].move(hdc) == FALSE)
- testAlive++;
- else
- {
- // Implement random intensity of colour change.
- // set intensity difference;
- int intChange = 15;
- COLORREF colChange = pFlares[count].getColour();
- int r = GetRValue(colChange);
- int g = GetGValue(colChange);
- int b = GetBValue(colChange);
-
- // Determine upward or downward change
- if (random(2))
- {
- // Upward change
- if ((r += intChange) > 255)
- r -= intChange;
-
- if ((g += intChange) > 255)
- g -= intChange;
-
- if ((b += intChange) > 255)
- b -= intChange;
- }
- else
- {
- // Downward change
- if ((r -= intChange) < 0)
- r += intChange;
-
- if ((g -= intChange) < 0)
- g += intChange;
-
- if ((b -= intChange) < 0)
- b += intChange;
- }
-
- pFlares[count].setColour(RGB(r, g, b));
- }
- }
-
- // Test if flares are still active.
- if (testAlive == flareNum)
- return FALSE;
- else
- return TRUE;
- }
-
- return TRUE;
- }
-
- // ############################################################################
- // ############################################################################
- // ############################################################################